package com.ljf.tijian.service;

import com.ljf.tijian.dto.ApiResponse;
import com.ljf.tijian.dto.CheckmealDetailedDto;
import com.ljf.tijian.mapper.CheckItemMapper;
import com.ljf.tijian.mapper.CheckItemdetailedMapper;
import com.ljf.tijian.pojo.Cidetailedreport;
import com.ljf.tijian.pojo.Cireport;
import com.ljf.tijian.service.Impl.CheckItemDetailedServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CheckItemDetailedService implements CheckItemDetailedServiceImpl {

    @Autowired
    CheckItemMapper checkItemMapper;

    @Autowired
    CheckItemdetailedMapper checkItemdetailedMapper;

    @Override
    public ApiResponse getCheckItemdetailedDto(Integer smId) {
        List<CheckmealDetailedDto> list = new ArrayList<>();

        List<Cireport> cireports = checkItemMapper.selectCheckItemBySmId(smId);
        for (Cireport cireport : cireports) {
            CheckmealDetailedDto checkmealDetailedDto = new CheckmealDetailedDto();
            checkmealDetailedDto.setCiId(cireport.getCiId());
            checkmealDetailedDto.setCiName(cireport.getCiName());
            list.add(checkmealDetailedDto);
        }
        for (CheckmealDetailedDto checkmealDetailedDto : list) {
            checkmealDetailedDto.setList(new ArrayList<>());
        }
        List<Cidetailedreport> cidetailedreports = checkItemdetailedMapper.selectCheckItemdetailedBySmId(smId);
        for (Cidetailedreport cidetailedreport : cidetailedreports) {
            for (CheckmealDetailedDto checkmealDetailedDto : list) {
                if(checkmealDetailedDto.getCiId() == cidetailedreport.getCiId()) checkmealDetailedDto.getList().add(cidetailedreport);
            }
        }

        return new ApiResponse(200,"SUCCESS",list);
    }
}
